#include "MsgConnect.h"
#include "EventMgr.h"



namespace cupid
{

MsgConnect::MsgConnect()
{
	init();
	m_template	=(msg_connect *)m_bufMsg;

}

MsgConnect::~MsgConnect()
{

}

//////////////////////////////////////////////////////////////////////
BOOL MsgConnect::create(const char* szName, const char* szPassword)
{
	// param check
	if (!szName || strlen(szName) >= _MAX_NAMESIZE)
		return false;

	// init
	this->init();

	// fill info now
	m_template->m_size	=sizeof(msg_connect);
	m_template->m_type	=msg_type_connect;

	strcpy_s(m_template->m_name, szName);
	strcpy_s(m_template->m_password, szPassword);

	return true;
}

//////////////////////////////////////////////////////////////////////
BOOL MsgConnect::create(char* bufMsg, DWORD dwMsgSize)
{
	if (!NetMsg::create(bufMsg, dwMsgSize))
		return false;

	return true;
}

//////////////////////////////////////////////////////////////////////
void MsgConnect::process( void* info )
{
	switch (m_template->m_subType)
	{
	case msg_subtype_signup:
		{
			MsgSn sn;
			sn << getSocketID();
			sn << string(m_template->m_name);
			sn << string(m_template->m_password);
			sEventMgr->trigger(event_signup, &sn);

		}
		break;
	case msg_subtype_signin:
		{
			MsgSn sn;
			sn << getSocketID();
			sn << string(m_template->m_name);
			sn << string(m_template->m_password);
			sEventMgr->trigger(event_signin, &sn);
		}
		break;
	}
}

}